﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Searching.Data
{
    class PageStore
    {
        private static PageStore instance;
        private static List<WebPage> pages;

        private PageStore()
        {
            pages = new List<WebPage>();
        }

        public static PageStore GetInstance()
        {
            if (instance == null)
            {
                instance = new PageStore();

                pages.Add(new WebPage("P1", new string[] {"程序设计", "算法", "软件"}));
                pages.Add(new WebPage("P2", new string[] { "计算机", "算法", "hello" }));
                pages.Add(new WebPage("P3", new string[] { "算法", "2", "hello" }));
                pages.Add(new WebPage("P4", new string[] { "1", "2", "hello" }));
                pages.Add(new WebPage("P5", new string[] { "3", "2", "hello" }));
                pages.Add(new WebPage("P6", new string[] { "6", "2", "hello" }));
            }
            return instance;
        }
        
        public bool AddPage(WebPage page)
        {
            if (pages.Count > 29)
                return false;
            else
                pages.Add(page);
            return true;
        }
        public bool DeletePage(int index)
        {
            if (pages.Count <= index)
                return false;
            else
                pages.RemoveAt(index);
            return true;
        }
        public void DeleteAll()
        {
            pages.Clear();
        }
        public WebPage[] GetAllPages()
        {
            return pages.ToArray();
        }
        public void RestPages(WebPage [] webPages)
        {
            pages.Clear();
            for (int i = 0; i < webPages.Length; ++i )
            {
                pages.Add(webPages[i]);
            }
        }
    }
}
